package cn.hfatec.shms.web.td.tdDate.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.td.tdDate.model.TdDate;
import cn.hfatec.shms.web.td.tdDate.dao.TdDateDao;
import cn.hfatec.shms.web.td.tdDate.model.TdDateParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("TdDateService")
public class TdDateService {

    public static final String BEAN_ID = "TdDateService";

    //注入Dao层
    @Resource(name = "TdDateDao")
    private TdDateDao tdDateDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param tdDateParams
     * @param page
     *
     */
    @Transactional
    public Table queryTdDateTable(TdDateParams tdDateParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", tdDateParams);
        return baseDao.queryTableByPage("queryTdDate", params, page);
    }

    /**
     *
     * 插入数据
     * @param tdDate
     *
     */
    @Transactional
    public void saveTdDate(TdDate tdDate) {
        if(tdDate.getId() != null) {
            TdDate result = getTdDate(tdDate.getId());
            if(result != null) {
                tdDateDao.update(tdDate);
            } else {
                tdDateDao.insert(tdDate);
            }
        } else {
            tdDateDao.insert(tdDate);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteTdDate(Integer id) {

        tdDateDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param tdDateList
     *
     */
    @Transactional
    public void deleteTdDateBatch(List<String> tdDateList) {
        for(String id : tdDateList) {
            deleteTdDate(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public TdDate getTdDate(Integer id) {

        return tdDateDao.getTdDateById(id);
    }
}